package com.whmskj.xjlhbc.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
//安全上报实体类
@Data
@TableName("bcsc16SecurityReport")
public class Bcsc16SecurityReport {
    private Long id;
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate dateport;      // 日期
    private String responb;          // 责任部门
    private String inspection;       // 巡查内容
    private String evaluation;       // 考核/教育
    private BigDecimal amount;       // 金额
    @JsonIgnore
    private String onsite;           // 现场图片(JSON 数组字符串)
    private String remarks;          // 备注
    private String reporter;         // 发现人/上报人
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime subtime;   // 提交时间
    private String confirmedStatus;  // 确认状态：待确认/已确认

    @TableField(exist = false)
    @JsonProperty(access = JsonProperty.Access.READ_WRITE)
    private java.util.List<java.util.Map<String,Object>> photos; // 照片对象数组（对外入参/出参）

    public java.util.List<java.util.Map<String,Object>> getPhotos() {
        if (photos != null) return photos;
        if (onsite == null || onsite.trim().isEmpty()) return java.util.Collections.emptyList();
        String s = onsite.trim();
        try {
            com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper();
            // 优先按对象数组解析
            photos = om.readValue(s, new com.fasterxml.jackson.core.type.TypeReference<java.util.List<java.util.Map<String,Object>>>(){});
            return photos;
        } catch (Exception ignore) {
            // 兼容：字符串数组 ["url1","url2"]
            try {
                com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper();
                java.util.List<String> urls = om.readValue(s, new com.fasterxml.jackson.core.type.TypeReference<java.util.List<String>>(){});
                java.util.List<java.util.Map<String,Object>> list = new java.util.ArrayList<>();
                for (String u : urls) {
                    if (u == null) continue;
                    String us = u.trim();
                    if (us.isEmpty()) continue;
                    java.util.Map<String,Object> m = new java.util.LinkedHashMap<>();
                    m.put("url", us);
                    list.add(m);
                }
                photos = list;
                return photos;
            } catch (Exception ignore2) {
                // 兼容：逗号分隔的旧格式
                String cleaned = s.replace("[", "").replace("]", "").replace("\"", "");
                if (cleaned.isEmpty()) return java.util.Collections.emptyList();
                String[] arr = cleaned.split(",");
                java.util.List<java.util.Map<String,Object>> list = new java.util.ArrayList<>();
                for (String it : arr) {
                    String v = it == null ? null : it.trim();
                    if (v == null || v.isEmpty()) continue;
                    java.util.Map<String,Object> m = new java.util.LinkedHashMap<>();
                    m.put("url", v);
                    list.add(m);
                }
                photos = list;
                return photos;
            }
        }
    }
}


